-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement choice #36
base: main
Are you sure you want to change the base?
Implement choice #36
Conversation
4318d43
to
5495f12
Compare
base: "John".to_string(), | ||
scope: None, | ||
}), | ||
lastname: None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case I expect more to retrieve an enum here.
The test is not easy to understand as a person has basically a first name and a last name, so it's not a choice, more a combination.
I think the example here is more relevant: https://www.w3schools.com/xml/el_choice.asp
Where. Person may have role employee
or member
.
So for me the expected code will be:
let model = Person::Employee("John".to_string());
// Generated part by xml-schema
enum Person {
Employee(String),
Member(String),
}
let model = Person { | ||
firstname: "John".to_string(), | ||
lastname: "".to_string(), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case I expect to have:
Person {
parents: vec![Parent::Firstname("John".to_string())],
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup exactly, I just patched this in one commit just to get it to compile. I am currently working on making this a vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry I just implemented:
let model = Person {
firstname_list: vec!["John".to_string()],
lastname_list: vec![],
};
which i notice now is a bit different from what you imagined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some attempts which try to implement this as enum, you can see the last commit here: 740c37b
Unforuntately the test fails with:
thread 'choice_multiple' panicked at xml_schema/tests/choice.rs:99:3:
assertion `left == right` failed
left: Gift { content: [] }
right: Gift { content: [price_history(1), price_history(3)] }
So I probably got the yaserde config wrong :(
I will pause this work for now.
Some things still to do:
Supersedes #20